package com.situ.water_system.controller;


import com.situ.water_system.pojo.SyArea;
import com.situ.water_system.service.SyAreaService;
import org.apache.ibatis.annotations.Delete;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/SyArea")
public class SyAreaController {
    @Autowired
    private SyAreaService service;
    @RequestMapping("/queryall")
    public List<SyArea> queryall() {
        return service.selectList();
    }
    @RequestMapping("/queryByid/{id}")
    public SyArea queryByid(@PathVariable(name = "id") Integer id) {
        return service.selectByid(id);
    }
    @RequestMapping("/del/{id}")
    public int del(@PathVariable(name = "id") Integer id) {
        return service.del(id);
    }
    @RequestMapping("/add")
    public int insert(SyArea syArea) {
        return service.add(syArea);
    }
    @RequestMapping("/update")
    public int update(SyArea syArea) {
        return service.update(syArea);
    }
    @RequestMapping(value = "/export/goods",method = RequestMethod.GET)
    public void goodsExcel(HttpServletResponse response) {
        XSSFWorkbook wb = service.select_excel();
        String fileName = "SyArea报表.xlsx";
        OutputStream outputStream = null;
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
            //设置ContentType请求信息格式
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

